gl: Add 'use-es' flag
authorEmmanuele Bassi <ebassi@gnome.org>
Mon, 18 Apr 2016 09:10:30 +0000 (10:10 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 25 Apr 2016 11:29:36 +0000 (12:29 +0100)
On some platforms we can ask the GL context machinery to create a GLES
context, instead of a GL one.

In order to ask for a GLES context at GdkGLContext realization time, we
use a bit field like we do for forward compatible, or debug contexts.

The 'use-es' bit also changes the way we select a default version,
because OpenGL and OpenGLES versions differ.

https://bugzilla.gnome.org/show_bug.cgi?id=743746

gdk/gdkglcontext.c
gdk/gdkglcontext.h
gdk/gdkglcontextprivate.h

index 00a33eb28fac58b24277d1e7b5491b59bd8239df..00a2c78e3f9c1dd94e71603b3f492d2f733191c9 100644 (file)
@@ -104,6 +104,7 @@ typedef struct {
   guint debug_enabled : 1;
   guint forward_compatible : 1;
   guint is_legacy : 1;
+  guint use_es : 1;
 
   GdkGLContextPaintData *paint_data;
 } GdkGLContextPrivate;
@@ -496,8 +497,8 @@ gdk_gl_context_set_required_version (GdkGLContext *context,
                                      int           major,
                                      int           minor)
 {
-  int version;
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+  int version, min_ver;
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
   g_return_if_fail (!priv->realized);
@@ -512,10 +513,16 @@ gdk_gl_context_set_required_version (GdkGLContext *context,
 
   /* Enforce a minimum context version number of 3.2 */
   version = (major * 100) + minor;
-  if (version < 302)
+
+  if (!priv->use_es)
+    min_ver = 302;
+  else
+    min_ver = 200;
+
+  if (version < min_ver)
     {
       g_warning ("gdk_gl_context_set_required_version - GL context versions less than 3.2 are not supported.");
-      version = 302;
+      version = min_ver;
     }
   priv->major = version / 100;
   priv->minor = version % 100;
@@ -538,19 +545,31 @@ gdk_gl_context_get_required_version (GdkGLContext *context,
                                      int          *minor)
 {
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+  int default_major, default_minor;
   int maj, min;
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
 
+  if (!priv->use_es)
+    {
+      default_major = 3;
+      default_minor = 2;
+    }
+  else
+    {
+      default_major = 2;
+      default_minor = 0;
+    }
+
   if (priv->major > 0)
     maj = priv->major;
   else
-    maj = 3;
+    maj = default_major;
 
   if (priv->minor > 0)
     min = priv->minor;
   else
-    min = 2;
+    min = default_minor;
 
   if (major != NULL)
     *major = maj;
@@ -603,6 +622,23 @@ gdk_gl_context_set_is_legacy (GdkGLContext *context,
   priv->is_legacy = !!is_legacy;
 }
 
+void
+gdk_gl_context_set_use_es (GdkGLContext *context,
+                           gboolean      use_es)
+{
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+
+  priv->use_es = !!use_es;
+}
+
+gboolean
+gdk_gl_context_get_use_es (GdkGLContext *context)
+{
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+
+  return priv->use_es;
+}
+
 /**
  * gdk_gl_context_realize:
  * @context: a #GdkGLContext
index daacd1e0c732ed2db4e8278dcb21df8406ac5ccf..44633a7c8a8f1d199f351c91ced1a037a26ffb4a 100644 (file)
@@ -73,6 +73,11 @@ void                    gdk_gl_context_set_forward_compatible   (GdkGLContext  *
                                                                  gboolean       compatible);
 GDK_AVAILABLE_IN_3_16
 gboolean                gdk_gl_context_get_forward_compatible   (GdkGLContext  *context);
+GDK_AVAILABLE_IN_3_22
+void                    gdk_gl_context_set_use_es               (GdkGLContext  *context,
+                                                                 gboolean       use_es);
+GDK_AVAILABLE_IN_3_22
+gboolean                gdk_gl_context_get_use_es               (GdkGLContext  *context);
 
 GDK_AVAILABLE_IN_3_16
 gboolean                gdk_gl_context_realize                  (GdkGLContext  *context,
index 348c16824df6b87ab55c3b508dd4e61108c5208b..46604942f6b50d1b0fdbd685a2cc214ca6430cd0 100644 (file)
@@ -69,6 +69,7 @@ typedef struct {
   GdkGLContextProgram *current_program;
 
   guint is_legacy : 1;
+  guint use_es : 1;
 } GdkGLContextPaintData;
 
 void                    gdk_gl_context_set_is_legacy            (GdkGLContext    *context,